<template>
  <views class="facilitator_list">
    <viewTitle :title="'服务商列表'" :border="true"></viewTitle>
    <div class="search_list">
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="flex flexR center">
          <div class="inputW flex flexR center">
            <el-form-item label="所属地区:" label-width="72px">
            <el-select v-model="province" placeholder="所属地区" filterable clearable>
              <el-option
                      v-for="item in province_select_list"
                      :key="item.region_id"
                      :label="item.name"
                      :value="item.region_id"
              ></el-option>
            </el-select>
          </el-form-item>
          </div>
          <div class="inputW flex flexR center">
            <el-form-item label="服务商编号:">
              <el-input type="text" clearable placeholder="服务商编号" v-model="facilitator_sn"></el-input>
            </el-form-item>
          </div>

          <div class="inputW flex flexR center">
            <el-form-item label="服务商名称:">
              <el-input
                type="text"
                clearable
                placeholder="服务商名称"
                v-model="facilitator_name"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="flex flexR">
          <el-form-item label="创建时间:">
            <el-date-picker
              v-model="facilitator_created_time"
              value-format="timestamp"
              type="datetimerange"
              :default-time="['0:00:00','23:59:59']"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              align="right"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <div class="search_unit">
              <el-button type="primary" @click="query()" icon="el-icon-search">查询</el-button>
              <el-button @click="reset()" icon="el-icon-refresh">重置</el-button>
              <el-button
                type="primary"
                :style="{width:140+'px'}"
                @click="exportExcel"
                size="medium"
                icon="el-icon-download"
              >导出列表</el-button>
              <el-button type="danger" @click="facilitator_add()" v-show="isAdd">新增</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>

    <div class="table_data">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号" fixed="left" width="100"></el-table-column>
        <el-table-column prop="facilitator_sn" label="服务商编号" width="150"></el-table-column>
        <el-table-column prop="facilitator_name" label="服务商名称" width="200"></el-table-column>
        <el-table-column prop="facilitator_user" label="初始管理员账号" width="200"></el-table-column>
        <el-table-column prop="facilitator_bank_code" label="服务商入户账号" width="250"></el-table-column>
        <el-table-column prop="contact_name" label="联系人" width="120"></el-table-column>
        <el-table-column prop="contact_mobile" label="联系人手机" width="150"></el-table-column>
        <el-table-column prop="facilitator_code" label="统一信用代码" width="250"></el-table-column>
        <el-table-column prop="region_name" label="所属地区" width="120"></el-table-column>
        <el-table-column prop="address" label="单位地址" width="200"></el-table-column>
        <el-table-column prop="facilitator_created_time" label="创建时间" width="200"></el-table-column>
        <el-table-column fixed="right" label="操作" width="250">
          <template slot-scope="scope">
            <el-button @click="look(scope.row.facilitator_id)" v-show="isLook">查看</el-button>
            <el-button type="primary" @click="edit(scope.row.facilitator_id)" v-show="isEdit">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paging flex flexR">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="handleSizeChange($event)"
          @current-change="changePage($event)"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>





<script>
export default {
  name: "FacilitatorList",
  data() {
    return {
      pickerOptions: {
        //企业创建时间快捷方式选择插件
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      province_select_list: [], //所属地区，省份选择
      province: "", //选择的服务商ID
      facilitator_created_time: [], //服务商创建时间范围
      facilitator_sn: "", //服务商编号
      facilitator_name: "", //服务商名称
      tableData: [], //表格数据
      download_url: "",
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    };
  },
  mounted() {
    //获取省份信息
    this.getProviceList();
    //获取服务商列表信息
    this.query();
  },
  computed: {
    //实时计算要传输的编辑参数
    post_data() {
      let data = {};
      if (
        this.facilitator_created_time &&
        this.facilitator_created_time.length > 0
      ) {
        data.facilitator_created_start_time =  this.facilitator_created_time[0]/1000;
        data.facilitator_created_end_time = this.facilitator_created_time[1]/1000;
      }
      data.facilitator_sn = this.facilitator_sn;
      data.facilitator_name = this.facilitator_name;
      data.province = this.province;
      data.pagination = this.pagination;
      return data;
    },
    isAdd(){      //判断是否具有 “新增” 按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].add ? 1 : 0;
    },
    isEdit(){     //判断是否具有  “编辑”  按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].edit ? 1 : 0;
    },
    isLook(){      //判断是否具有 “查看” 按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].look ? 1 : 0;
    },
    isLook() {
      //判断是否具有 “查看” 按钮权限
      return this.$store.state.buttonPermission[this.$route.path].look ? 1 : 0;
    }
  },
  methods: {
    facilitator_add() {
      //跳转到新增服务商页面
      this.$toRoutePath({
        path: "/facilitator_list/facilitator_list_add",
        edit: true
      });
    },
    getProviceList() {
      //获取省份信息
      this.$raxios
        .post(this.$mapapi.get_region, {})
        .then(res => {
          if (res.code != 200 && res.code != 501)
            return Promise.reject(res.msg);
          this.province_select_list = res.data;
        })
        .catch(res => {
          this.$message.error(res);
        });
    },
    handleSizeChange(page_size) {
      //变动每页数量时
      this.pagination.page_size = page_size;
      this.query();
    },
    changePage(current_page) {
      //切换页码时
      this.pagination.page_start = current_page;
      this.query();
    },
    query() {
      //服务商列表
      this.$raxios
        .post(this.$mapapi.facilitatorList, { data: this.post_data })
        .then(res => {
          if (res.code != 200 && res.code != 501)
            return Promise.reject(res.msg);
          this.tableData = res.data.list;
          this.pagination = res.data.pagination;
          this.download_url = res.data.download_url || "";
        })
        .catch(res => {
          this.$message.error(res);
        });
    },
    //导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    reset() {
      //重置
      this.facilitator_created_time = [];
      this.facilitator_sn = "";
      this.facilitator_name = "";
      this.province = "";
      this.query();
    },
    look(facilitator_id) {
      //查看某个服务商
      this.$toRoutePath({
        path: "/facilitator_list/facilitator_list_look",
        edit: true,
        query: { facilitator_id }
      });
    },
    edit(facilitator_id) {
      //编辑某个服务商
      this.$toRoutePath({
        path: "/facilitator_list/facilitator_list_amend",
        edit: true,
        query: { facilitator_id }
      });
    }
  }
};
</script>

<style  lang="less" :scope="true" src="@/style/facilitator/facilitator_list.less">
</style>
